home *** CD-ROM | disk | FTP | other *** search
/ TestDrive Windows 1993 Fall / TestDrive Windows 1993 Fall.iso / dbase / samples / onmouse.prg < prev    next >
Encoding:
Text File  |  1993-03-09  |  5.2 KB  |  148 lines

  1. PROCEDURE OnMouse
  2. *--------------------------------------------------------------------
  3. * DESCRIPTION
  4. *   OnMouse demonstrates how you can use the new ON MOUSE in an
  5. *   event loop to click between two Browse displays.  OnMouse
  6. *   uses two DBF files, Transact and Stock.  For each Transact
  7. *   record, there can be zero or more Stock records linked using
  8. *   the OrderId field.  In addition to clicking, OnMouse shows
  9. *   how you can use the F3 or F4 key to click between the Browse
  10. *   windows.
  11. *--------------------------------------------------------------------
  12.  
  13.   SET TALK OFF
  14.   SET COLOR TO W+/B
  15.   SET STATUS OFF
  16.   USE Transact IN 1
  17.   USE Stock ORDER Order_Id IN 2
  18.   DEFINE WINDOW Transact FROM 2,2 TO 10,77  && Windows for browsing Transact
  19.   DEFINE WINDOW Stock FROM 12,2 TO 19,77    && and Stock files
  20.  
  21.   @ 22, 36 SAY "  Quit  " COLOR w+/g    && Display the Quit button
  22.   @ 22, 38 SAY "Q" COLOR gr+/g          && Highlite the Q for Alt-Q pick
  23.  
  24.   @ 1, 2 SAY "Transact: Click on lower browse to view related Stock"
  25.   @ 20, 2 SAY "Stock: Click on upper browse to view new Transact record"
  26.   @ 24, 18 SAY "Click on Quit button or press Alt-Q to exit."
  27.  
  28.   KEYBOARD "{27}"                       && Get out of browse after display
  29.   DO ShowTran                           && Display the Transact browse
  30.   KEYBOARD "{27}"
  31.   DO ShowStock                          && Display the Stock browse
  32.   ON MOUSE DO MouseHand WITH MROW(), MCOL()
  33.   ON KEY LABEL Alt-Q DO KeyHand WITH "Q"
  34.   ON KEY LABEL F3    DO KeyHand WITH "F3"
  35.   ON KEY LABEL F4    DO KeyHand WITH "F4"
  36.   nCurrent = 1                          && 1 for Transact, 2 for Stock
  37.   lQuit = .F.
  38.   *-- Do the event loop until the Quit button is pressed
  39.   DO WHILE .NOT. lQuit                  && lQuit is set to .T. in MouseHand
  40.     DO CASE
  41.       CASE nCurrent = 1                 && Browse Transact file if 1
  42.         DO ShowTran
  43.       CASE nCurrent = 2                 && Browse Stock file if 2
  44.         DO ShowStock
  45.     ENDCASE
  46.   ENDDO
  47.   ON MOUSE                              && Clear the ON MOUSE
  48.   ON KEY LABEL F3                       && and ON KEY settings
  49.   ON KEY LABEL F4
  50.   ON KEY LABEL Alt-Q
  51.  
  52.   RELEASE WINDOW Transact
  53.   RELEASE WINDOW Stock
  54.   USE IN 2
  55.   USE IN 1
  56.   SET STATUS ON
  57. RETURN
  58.  
  59. PROCEDURE MouseHand
  60. PARAMETERS pn_MRow, pn_MCol
  61. *--------------------------------------------------------------------
  62. * DESCRIPTION
  63. *   MouseHand is the mouse event handler for the event loop.
  64. *   MouseHand will respond to the following actions:
  65. *
  66. *     Click on quit button: Set lQuit flag to .T. to exit
  67. *     Click in Transact:    Set nCurrent to 1 if in Stock window
  68. *     Click in Stock:       Set nCurrent to 2 if in Transact window
  69. *
  70. *   MouseHand will then keyboard an Escape to exit the active browse
  71. *   window and return control back to the event loop.
  72. *--------------------------------------------------------------------
  73.  
  74.   DO CASE
  75.     CASE pn_MRow = 22 .AND. pn_MCol >= 36 .AND. pn_MCol <= 43
  76.       lQuit = .T.
  77.     CASE pn_MRow >= 2 .AND. pn_MRow <= 10 .AND. ;
  78.          pn_MCol >= 2 .AND. pn_MCol <= 77
  79.       nCurrent = 1
  80.     CASE pn_MRow >= 12 .AND. pn_MRow <= 19 .AND. ;
  81.          pn_MCol >= 2 .AND. pn_MCol <= 77
  82.       nCurrent = 2
  83.   ENDCASE
  84.   KEYBOARD "{27}"                       && Escape out of current browse
  85.  
  86. RETURN
  87. *-- EOP: MouseHand
  88.  
  89.  
  90. PROCEDURE KeyHand
  91. PARAMETERS pc_KeyCode
  92. *--------------------------------------------------------------------
  93. * DESCRIPTION
  94. *   KeyHand is the keyboard event handler for the event loop.
  95. *   KeyHand will respond to the following actions:
  96. *
  97. *     On F3:    Flip nCurrent to 1 if 2 or 2 if 1
  98. *     On F4:    Flip nCurrent to 1 if 2 or 2 if 1
  99. *     On Alt-Q: Set lQuit flag to .T. to exit
  100. *
  101. *   KeyHand will then keyboard an Escape to exit the active browse
  102. *   window and return control back to the event loop.
  103. *--------------------------------------------------------------------
  104.  
  105.   DO CASE
  106.     CASE pc_KeyCode = "Q"
  107.       lQuit = .T.
  108.     CASE pc_KeyCode = "F4"
  109.       nCurrent = IIF( nCurrent = 1, 2, 1 )
  110.     CASE pc_KeyCode = "F3"
  111.       nCurrent = IIF( nCurrent = 1, 2, 1 )
  112.   ENDCASE
  113.   KEYBOARD "{27}"                       && Escape out of current browse
  114.  
  115. RETURN
  116. *-- EOP: KeyHand
  117.  
  118.  
  119. PROCEDURE ShowTran
  120. *--------------------------------------------------------------------
  121. * DESCRIPTION
  122. *   Browse the Transact file inside of a window
  123. *--------------------------------------------------------------------
  124.   SELECT Transact
  125.   BROWSE WINDOW Transact NOCLEAR COMPRESS NOINIT
  126. RETURN
  127. *-- EOP: ShowTran
  128.  
  129.  
  130. PROCEDURE ShowStock
  131. *--------------------------------------------------------------------
  132. * DESCRIPTION
  133. *   Browse the Stock records linked to the Transact file inside
  134. *   of a window.  If there is no match, display all the Stock
  135. *   records.
  136. *--------------------------------------------------------------------
  137.   SELECT Stock
  138.   SET KEY TO Transact->Order_id         && Display records that match order
  139.   IF EOF()                              && If no records match, then
  140.     SET KEY TO                          && display all the Stock records
  141.     GO TOP
  142.   ENDIF
  143.   BROWSE WINDOW Stock NOCLEAR COMPRESS NOINIT
  144. RETURN
  145. *-- EOP: ShowStock
  146.  
  147.  
  148.